#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include "cppjieba/Jieba.hpp"

namespace ns_util
{
    class FlieUtil
    {
    public:
        static bool ReadFlie(const std::string &file_path, std::string *out)
        {
            // 打开文件
            std::ifstream in(file_path, std::ios::in);
            if (!in.is_open())
            {
                std::cerr << "open error:" << file_path << std::endl;
                return false;
            }

            std::string line;
            // getline读取结束的标志是什么？
            while (std::getline(in, line)) // getline的返回只是一个&，但是while(bool),这是因为这里进行了强制类型转换
            {
                *out += line;
            }
            return true;
        }
    };

    class StringUtil
    {
    public:
        // line results sep
        // 切割字符串
        // aaaaa\3bbbbb\3\3\3\3\3\3cccccc
        // boost::token_compress_on就是去除多余的\3
        static void Split(const std::string &target, std::vector<std::string> *out, const std::string &sep)
        {
            boost::split(*out, target, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    // 词库
    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";

    //分词功能的实现
    class JiebaUtil
    {
    private:
        // 定义一个jieba对象
        static cppjieba::Jieba jieba;
    public:
        static void CutString(const std::string& src, std::vector<std::string> *out)
        {
            jieba.CutForSearch(src, *out);
        }
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);

}